package pl.krgr.vm2.ui.actions;

import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import pl.vm.model.OfficialTeam;
import pl.vm.model.Seazon;
import pl.vm.service.SeazonService;

import com.opensymphony.xwork2.ActionSupport;

public class SeazonAction extends ActionSupport {

	private static final long serialVersionUID = 1L;

	@Autowired
	private SeazonService seazonService;
	private Long seazonId;
	private List<OfficialTeam> officialTeams = new LinkedList<OfficialTeam>();
	private Seazon seazon;
	
	public String execute() throws Exception {
		seazon = seazonService.getSeazon(seazonId);
		officialTeams.addAll(seazon.getOfficialTeams());
		Collections.sort(officialTeams, new Comparator<OfficialTeam>() {

			public int compare(OfficialTeam o1, OfficialTeam o2) {
				return o1.getName().compareTo(o2.getName());
			}
			
		});
		return SUCCESS;
	}

	public List<OfficialTeam> getOfficialTeams() {
		return this.officialTeams;
	}
	
	public String getSeazonName() {
		return seazon.getName();
	}

	public void setSeazonId(long seazonId) {
		this.seazonId = seazonId;
	}

	public Seazon getSeazon() {
		return seazon;
	}

	public void setSeazon(Seazon seazon) {
		this.seazon = seazon;
	}
	
}
